package com.woniuxy.redis01.consumer;

import cn.hutool.extra.mail.MailUtil;
import com.rabbitmq.client.Channel;
import com.woniuxy.redis01.entity.Student;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 作者
 * @create 2025-06-25 14:19
 */
@Component
public class EmailConsumer {

    @RabbitListener(queues = "queueemail")
    public void doEmail(Student student, Message message, Channel channel) throws IOException {

        System.out.println("接收到消息："+student);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        try {
//            //业务层处理
//            //处理成功，确认，服务器删除消息
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        } catch (IOException e) {
//            //long deliveryTag,
//            // boolean multiple,
//            // boolean requeue
//            //处理失败，requeue-true，重回队列
//            //requeue-false，不重回队列
////            channel.basicNack(deliveryTag, multiple, requeue);
//        }


//        MailUtil.send("chinasofti_lbs@163.com", "找回密码", "验证码:"+code, false);
//        try {
//            if(true){
//                throw new RuntimeException("email消费处理异常");
//            }
//        } catch (RuntimeException e) {
//            System.out.println("记录日志，数据库，人工干预");
//        }
    }
}
